package guestbook;

import java.util.*;

public class Tally
{
	public Context context;

	public static final boolean ON = true;

	public Map<String, Integer> callsTable = new HashMap<String, Integer>();

	public Tally(Context context)
	{
		this.context = context;
	}

	public void tallyCall(String method)
	{
		Integer o = callsTable.get(method);
		callsTable.put(method, o == null ? 1 : o.intValue() + 1);
	}

	public void print()
	{
		print(context.getCurrentPage().toString());
	}

	public void print(String pageInfo)
	{
		System.out.print("[" + pageInfo + "] ");

		int tally = 0;

		for (String key : callsTable.keySet())
		{
			int calls = callsTable.get(key);
			tally += calls;
			System.out.print(key + ":" + calls + " ");
		}
		System.out.print(" >> total:" + tally);
		System.out.println();
	}

}
